/**
 * @author  MIoT
 * @date    2019
 * @par     Copyright (c):
 *
 *    Copyright 2019 MIoT,MI
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
#ifndef __USART_H
#define __USART_H
#include "stdio.h"	
#include "sh30f9871.h"
#include "user_config.h"       		


#define	DEBUG_UART				(UART2)
#define DEBUG_UART_RCC			(RCC_APB1_UART2)


#define WIFI_UART				(UART0)
#define WIFI_UART_RCC			(RCC_APB1_UART0)
#define WIFI_UART_IRQ			(UART0_IRQn)
#define WIFI_UART_HANDLER		(UART0_Handler)



#define LOOP_ADD(des,step_len,max_len) ((des + step_len) >= max_len) ? ((des +step_len) - max_len) : (des + step_len)

typedef enum _uart_error_t {
    UART_OK = 0,
    UART_DESTROY_ERROR	= -1,
    UART_OPEN_ERROR		= -2,
    UART_SET_ARRT_ERROR	= -3,
    UART_SEND_ERROR		= -4,
    UART_RECV_ACK_ERROR	= -5,
    UART_RECV_ERROR		= -6,
} uart_error_t;


#define WIFI_UART_DATA_LEN_MAX				(516)

typedef struct
{
		__IO uint16_t lenght;
		uint8_t buff[WIFI_UART_DATA_LEN_MAX];
}miio_ringbuff_t;
extern miio_ringbuff_t ring_buff;


void DebugUartInit(uint32_t boundrate);

void  Wifi_uart_init(void);


int Wifi_send_data(unsigned  char* data, unsigned short len);

int Wifi_send_Byte(unsigned  char data);

int Wifi_send_str_wait_ack(const char* str);

void WifiUartTickDec(void);

void SetWifiUartTick(int ms);

int GetWifiUartTick(void);


void Wifi_uart_interrupt(uint8_t enable);
#endif


